package com.qf.service.impl;

import com.qf.api.CacheFegin;
import com.qf.constant.CacheConstants;
import com.qf.model.StandardSubmit;
import com.qf.service.FilterChainService;
import com.qf.util.PushMsgUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;

/**
 * 黑名单策略
 */
@Service("black")
@Slf4j
public class BlackFilterServiceImpl implements FilterChainService {

    @Autowired
    private PushMsgUtil pushMsgUtil;
    @Resource
    private CacheFegin cacheFegin;
    @Override
    public boolean strategy(StandardSubmit standardSubmit) throws Exception {

        String s = cacheFegin.get(CacheConstants.CACHE_PREFIX_BLACK + standardSubmit.getDestMobile());

        //判断
        if ("1".equals(s)&&StringUtils.isEmpty(s)){
            pushMsgUtil.sendLog(standardSubmit,"该号码在黑名单中，发送短信失败");
            pushMsgUtil.pushReport(standardSubmit,"该号码在黑名单中，发送短信失败");
            return false;
        }
        log.info("黑名单策略执行成功");
        return true;
    }

}
